%% process_animation
function process_animation(fespace1, fespace2, U, vector_t)
x1 = fespace1.node(:,1);
y1 = fespace1.node(:,2);
x2 = fespace2.node(:,1);
y2 = fespace2.node(:,2);
shift_u2 = fespace1.Nb;
shift_p = 2*fespace1.Nb;
% interpolation
xg = linspace(min(x1), max(x1), 64);
yg = linspace(min(y1), max(y1), 64);
[X, Y] = meshgrid(xg, yg);
% figure and videos
fig1 = figure("Visible", "off");
ax1 = axes("Parent", fig1);
vid1 = VideoWriter("Animation_Velocity_Field.mp4", "MPEG-4");
vid2 = VideoWriter("Animation_Streamlines.mp4", "MPEG-4");
vid3 = VideoWriter("Animation_Pressure_Contours.mp4", "MPEG-4");
open(vid1);
open(vid2);
open(vid3);
for i = 1:size(U,2)
    t = vector_t(i);
    U_now = full(U(:,i));
    u1 = U_now(1:shift_u2);
    u2 = U_now(shift_u2+1:shift_p);
    p = U_now(shift_p+1:end);
    U1 = griddata(x1, y1, u1, X, Y);
    U2 = griddata(x1, y1, u2, X, Y);
    P = griddata(x2, y2, p, X, Y);
    figure(fig1);
    % Velocity Field
    cla(ax1);
    pcolor(ax1, X, Y, sqrt(U1.^2 + U2.^2));
    shading(ax1, "interp");
    colorbar(ax1);
    hold(ax1, "on");
    step = 2;
    h = quiver(ax1, X(1:step:end, 1:step:end), ...
        Y(1:step:end, 1:step:end), ...
        U1(1:step:end, 1:step:end), ...
        U2(1:step:end, 1:step:end), 2);
    h.Color = "w";
    title(ax1, sprintf("Velocity Field at t = %.4f", t));
    axis(ax1, "equal", "tight");
    hold(ax1, "off");
    frame = getframe(fig1);
    writeVideo(vid1, frame);
    % Streamlines
    cla(ax1);
    streamslice(ax1, X, Y, U1, U2, 2);
    colorbar(ax1, "off");
    title(ax1, sprintf("Streamlines at t = %.4f", t));
    axis(ax1, "equal", "tight");
    frame = getframe(fig1);
    writeVideo(vid2, frame);
    % Pressure Contours
    cla(ax1);
    contourf(ax1, X, Y, P, 20);
    colorbar(ax1);
    title(ax1, sprintf("Pressure Contours at t = %.4f", t));
    axis(ax1, "equal", "tight");
    frame = getframe(fig1);
    writeVideo(vid3, frame);
end
close(vid1);
close(vid2);
close(vid3);
end